#include <iostream>
#include <cstdlib>
#include <unistd.h>

using std::cerr;
using std::endl;


int main()
{
    std::string method = getenv("METHOD");
    std::string bodyText;
    if (method == "GET")
    {
        bodyText = getenv("QUERY") != NULL ? getenv("QUERY") : "";
        if(bodyText == "")
        {
            cerr << "get QUERY fail" << endl;
            return 2;
        }
    }
    else if (method == "POST")
    {
        int size = atoi(getenv("POSTSIZE"));
        char ch = 0; 
        while(size--)
        {
            read(0, &ch, 1);
            bodyText += ch;
        }
    }


    write(1, bodyText.c_str(), bodyText.size());
    return 0;
}